package com.ztrue.framework.infrastructure;

import com.ztrue.common.utilities.IdHelper;

import java.util.Date;

/**
 * 抽象消息
 *
 * @author zhangw
 * @date 2016/10/27 14:06
 * @version: 1.0
 */
public abstract class Message implements IMessage {
    private String id;
    private Date timestamp;
    private int sequence;

    public Message() {
        this.id = IdHelper.generateNewStringUUID();
        this.timestamp = new Date();
    }

    /**
     * 获取消息唯一编号
     *
     * @return
     */
    public String getId() {
        return id;
    }

    /**
     * 设置消息唯一编号
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * 获取消息时间戳
     *
     * @return
     */
    public Date getTimestamp() {
        return timestamp;
    }

    /**
     * 获取消息类型名称
     *
     * @return
     */
    public String getTypeName() {
        return this.getClass().getName();
    }

    /**
     * 获取序号
     *
     * @return
     */
    @Override
    public int getSequence() {
        return sequence;
    }

    /**
     * 设置序号
     *
     * @param sequence
     */
    public void setSequence(int sequence) {
        this.sequence = sequence;
    }
}
